# 1. j > i 时左边补空格
def print_nums(n):
    for i in range(1,n+1):
        for j in range(n,0,-1):
            print('{}'.format(' '*len(str(j)) if j > i else j),end='\n' if j==1 else ' ')
        #print()
print_nums(12)

print('#'*50)

# 2. 计算最后一行宽度，右对齐
def print_nums(n):
    r = [str(j) for j in range(n,0,-1)]
    tail =' '.join(r)
    width = len(tail)
    for i in range(n-1,0,-1):
        row =' '.join(r[i:])
        print('{:>{}}'.format(row,width))
    print(tail)

print_nums(12)

print('#'*50)

# 3.倒三角，计算最后一行，遇到空格切片
def print_nums(n):
    tail =' '.join([str(j) for j in range(n,0,-1)])
    width = len(tail)
    print(tail)
    for i,j in enumerate(tail,start=1):
        if j == ' ':
            row = tail[i:]
            print('{:>{}}'.format(row, width))

print_nums(12)

print('#'*50)

# 4.计算最后一行,rpartition 或 rsplit
def print_nums(n):
    tail =' '.join([str(j) for j in range(n,0,-1)])
    width = len(tail)
    for i in range(2,n+1):
        #row = tail.rpartition(str(i))[-1]
        row = tail.rsplit(str(i),maxsplit=1)[-1]
        print('{:>{}}'.format(row,width))
    print(tail)

print_nums(12)

print('#'*50)

# 5. 倒三角,rpartition 或 rsplit

def print_nums(n):
    pre =' '.join([str(j) for j in range(n,0,-1)])
    print(pre)
    width = len(pre)
    for i in range(n,1,-1):
        #row = pre.rpartition(str(i))[-1]
        row = pre.rsplit(str(i),maxsplit=1)[-1]
        print('{:>{}}'.format(row,width))

print_nums(12)


# 完成的很不错
